package Demo01;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28463
 * Date: 2022—05—15
 * Time: 21:11
 */
class Animal{
    private String name;
    private int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void eat() {
        System.out.println(name + " 正在吃饭！");
    }
    @Override
    public String toString() {
        return "Animal{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
class Dog extends Animal{

    public Dog(String name, int age) {
        super(name, age);
    }
    public void bark() {
        System.out.println(getName()+" 正在狗叫！");
    }

    @Override
    public void eat() {
        System.out.println(getName()+"正在吃狗粮！");
    }
}
class Bird extends Animal{

    public Bird(String name, int age) {
        super(name, age);
    }
    public void fly() {
        System.out.println(getName()+" 正在飞翔！");
    }
    @Override
    public void eat() {
        System.out.println(getName()+ " 吃鸟粮！");
    }
}
public class Test01 {
    public static void main(String[] args) {

    }
/*    public static void main(String[] args) {
        Animal animal = new Dog("小旺财",3);
        //判断 animal 是不是引用了 Bird 这个对象
        if(animal instanceof Bird) {
            Bird bird = (Bird) animal;//向下转型
            bird.fly();
        }
    }*/

/*    public static void main(String[] args) {
        Animal animal = new Bird("老鹰",3);
        Bird bird = (Bird) animal;//向下转型
        bird.fly();
    }*/




/*
    public static void function(Animal animal) {
        animal.eat();

    }

    public static void main1(String[] args) {
        function(new Bird("小鹦鹉 ",2));
        function(new Dog("小旺财 ",3));
    }
*/

    public static Animal func(){
        return new Bird("老鹰",3);
    }
/*    public static void main2(String[] args) {
        Bird bird= new Bird("老鹰",3);
        function(bird);
    }*/
    public static void main1(String[] args) {
/*        Bird bird = new Bird("老鹰",3);
        Animal animal = bird;
        animal.eat();*/
        //父类引用  引用了子类的对象
        // 向上转型
        //此时通过父类引用，只能调用父类自己特有的方法，不可以调用子类的方法
        Animal animal = new Bird("老鹰",3);
        animal.eat();

        //动态绑定
    }

/*    public static void main(String[] args) {
        Bird bird = new Bird("老鹰",3);
        bird.fly();
        bird.eat();*/
}

